package com.java110.mall.cart.api;

import com.alibaba.fastjson.JSONObject;
import com.java110.dto.storeOrder.StoreOrderCartSendDto;
import com.java110.po.storeOrder.StoreOrderCartSendPo;
import com.java110.mall.cart.bmo.storeOrderCartSend.IDeleteStoreOrderCartSendBMO;
import com.java110.mall.cart.bmo.storeOrderCartSend.IGetStoreOrderCartSendBMO;
import com.java110.mall.cart.bmo.storeOrderCartSend.ISaveStoreOrderCartSendBMO;
import com.java110.mall.cart.bmo.storeOrderCartSend.IUpdateStoreOrderCartSendBMO;
import com.java110.utils.util.Assert;
import com.java110.utils.util.BeanConvertUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping(value = "/storeOrderCartSend")
public class StoreOrderCartSendApi {

    @Autowired
    private ISaveStoreOrderCartSendBMO saveStoreOrderCartSendBMOImpl;
    @Autowired
    private IUpdateStoreOrderCartSendBMO updateStoreOrderCartSendBMOImpl;
    @Autowired
    private IDeleteStoreOrderCartSendBMO deleteStoreOrderCartSendBMOImpl;

    @Autowired
    private IGetStoreOrderCartSendBMO getStoreOrderCartSendBMOImpl;

    /**
     * F
     * 微信保存消息模板
     *
     * @param reqJson
     * @return
     * @serviceCode /storeOrderCartSend/saveStoreOrderCartSend
     * @path /app/storeOrderCartSend/saveStoreOrderCartSend
     */
    @RequestMapping(value = "/saveStoreOrderCartSend", method = RequestMethod.POST)
    public ResponseEntity<String> saveStoreOrderCartSend(@RequestBody JSONObject reqJson) {

        Assert.hasKeyAndValue( reqJson, "cartId", "请求报文中未包含cartId" );
        Assert.hasKeyAndValue( reqJson, "shopId", "请求报文中未包含shopId" );
        Assert.hasKeyAndValue( reqJson, "modeId", "请求报文中未包含modeId" );
        Assert.hasKeyAndValue( reqJson, "modeName", "请求报文中未包含modeName" );
        Assert.hasKeyAndValue( reqJson, "price", "请求报文中未包含price" );
        Assert.hasKeyAndValue( reqJson, "state", "请求报文中未包含state" );


        StoreOrderCartSendPo storeOrderCartSendPo = BeanConvertUtil.covertBean( reqJson, StoreOrderCartSendPo.class );
        return saveStoreOrderCartSendBMOImpl.save( storeOrderCartSendPo );
    }

    /**
     * 微信修改消息模板
     *
     * @param reqJson
     * @return
     * @serviceCode /storeOrderCartSend/updateStoreOrderCartSend
     * @path /app/storeOrderCartSend/updateStoreOrderCartSend
     */
    @RequestMapping(value = "/updateStoreOrderCartSend", method = RequestMethod.POST)
    public ResponseEntity<String> updateStoreOrderCartSend(@RequestBody JSONObject reqJson) {

        Assert.hasKeyAndValue( reqJson, "sendId", "请求报文中未包含sendId" );
        Assert.hasKeyAndValue( reqJson, "cartId", "请求报文中未包含cartId" );
        Assert.hasKeyAndValue( reqJson, "shopId", "请求报文中未包含shopId" );
        Assert.hasKeyAndValue( reqJson, "modeId", "请求报文中未包含modeId" );
        Assert.hasKeyAndValue( reqJson, "modeName", "请求报文中未包含modeName" );
        Assert.hasKeyAndValue( reqJson, "price", "请求报文中未包含price" );
        Assert.hasKeyAndValue( reqJson, "state", "请求报文中未包含state" );


        StoreOrderCartSendPo storeOrderCartSendPo = BeanConvertUtil.covertBean( reqJson, StoreOrderCartSendPo.class );
        return updateStoreOrderCartSendBMOImpl.update( storeOrderCartSendPo );
    }

    /**
     * 微信删除消息模板
     *
     * @param reqJson
     * @return
     * @serviceCode /storeOrderCartSend/deleteStoreOrderCartSend
     * @path /app/storeOrderCartSend/deleteStoreOrderCartSend
     */
    @RequestMapping(value = "/deleteStoreOrderCartSend", method = RequestMethod.POST)
    public ResponseEntity<String> deleteStoreOrderCartSend(@RequestBody JSONObject reqJson) {
        Assert.hasKeyAndValue( reqJson, "cartId", "请求报文中未包含cartId" );
        Assert.hasKeyAndValue( reqJson, "shopId", "请求报文中未包含shopId" );

        Assert.hasKeyAndValue( reqJson, "sendId", "sendId不能为空" );


        StoreOrderCartSendPo storeOrderCartSendPo = BeanConvertUtil.covertBean( reqJson, StoreOrderCartSendPo.class );
        return deleteStoreOrderCartSendBMOImpl.delete( storeOrderCartSendPo );
    }

    /**
     * 微信删除消息模板
     *
     * @param
     * @return
     * @serviceCode /storeOrderCartSend/queryStoreOrderCartSend
     * @path /app/storeOrderCartSend/queryStoreOrderCartSend
     */
    @RequestMapping(value = "/queryStoreOrderCartSend", method = RequestMethod.GET)
    public ResponseEntity<String> queryStoreOrderCartSend(@RequestParam(value = "cartId",required = false) String cartId,
                                                          @RequestParam(value = "shopId",required = false) String shopId,
                                                          @RequestParam(value = "sendId",required = false) String sendId,
                                                          @RequestParam(value = "page") int page,
                                                          @RequestParam(value = "row") int row) {
        StoreOrderCartSendDto storeOrderCartSendDto = new StoreOrderCartSendDto();
        storeOrderCartSendDto.setPage( page );
        storeOrderCartSendDto.setRow( row );
        storeOrderCartSendDto.setCartId( cartId );
        storeOrderCartSendDto.setShopId( shopId );
        storeOrderCartSendDto.setSendId( sendId );
        return getStoreOrderCartSendBMOImpl.get( storeOrderCartSendDto );
    }
}
